<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/resources/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/resources/css/bootstrap.min.css"/>
    <script src="/resources/js/jquery.min.js"></script>
    <script src="/resources/js/bootstrap.min.js"></script>
    <script src="/resources/layui/css/layui.css"></script>
    <script src="/resources/layui/layui.js"></script>
    <script src="/resources/js/vue.js"></script>
    <script src="/resources/js/bootstrap.js"></script>
</head>
<body>
<table id="demo" lay-filter="test"></table>
</body>
</html>


<script>
    var table;
    layui.use(['table',"laytpl","layer","form"],function(){
        table = layui.table;
        //第一个实例
        table.render({
            elem: '#demo'
            ,url: 'http://localhost:8888/panku/list' //数据接口
            ,page: true //开启分页
            ,toolbar:"#toolbarDemo"
            ,cols: [[ //表头
                {field:'hello',type:'checkbox'}
                ,{field: 'id', title: '编号'}
                ,{field: 'yewuId', title: '工作单号',templet:function (d) {
                        var str=" -";
                        if (d.yeweu!=null){
                            str=d.yeweu.id;
                        }
                        return str;
                    }}
                ,{field: 'scDate', title: '生成时间'}
                ,{field: 'address', title: '到达城市',templet:function (d) {
                        var strs = "-";
                        if (d.yeweu!=null) {
                            strs = d.yeweu.address;
                        }
                        return strs
                    }}
            ]]
        });
        table.on("toolbar(test)",function(obj){
            var zhi=obj.event;
            switch(zhi){
                case "add":
                    var idstr="";
                    var bbb=table.checkStatus('demo');
                    if(bbb.data.length>1){
                        for(let bb of bbb.data){
                            idstr+=bb.id+",";
                        }
                    }else{
                        return;
                    }
                    var chengshi=bbb.data[0].yeweu.address;
                    var zhen=false;
                    for(let bb of bbb.data){
                        if(chengshi!=bb.yeweu.address){
                            zhen=true;
                        }
                    }
                    if(zhen){
                        layui.layer.msg("不是一个城市无法合包！");
                        return;
                    }
                    $.get('http://localhost:8888/panku/add',{idstr:idstr,chengshi:chengshi},d=>{
                        layui.layer.msg("合包成功！");
                        table.reload('demo');
                    });
                    break;
            }
        })
    })
</script>



<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon layui-icon-add-circle"></i> 合包</button>
    </div>
</script>
